<?php
/* Author : IronLady */

  function zen_get_products_rating($pid) {
    global $db;
    $rating_query = $db->Execute("SELECT avg(reviews_rating) as avg 
                                 from " . TABLE_REVIEWS . " r
                                 where products_id='" . (int)$pid . "' limit 1");
    if ($rating_query->EOF) {
      return 0;
    } else {
      return round($rating_query->fields['avg']);
    }
  }

  function rev_change_color($color='#409F89'){
    if(defined('REVELATION_COLOR') && REVELATION_COLOR != ''){
        $color = REVELATION_COLOR;    
    }
    $style = '<style type="text/css">';
    $style .= 'a, .flex-direction-nav a:hover, .social, .dropdown-menu li > a:hover, .dropdown-menu li > a:focus, .dropdown-submenu:hover > a, .dropdown-menu .active > a, .dropdown-menu .active > a:hover, .indexProducts .price, .itemTitle a:hover , .name a:hover, #productPrices, #zoomImage:hover, .price, .productSpecialPrice, .productSalePrice, .productSpecialPriceSale, .productPriceDiscount, .footerBoxHeading, ul.categories-side li a:hover, ul.categories-side li a.side-active, .tweet_list li a, #scroller ul li a:hover, #scroller ul li .price, ul.categories-side li .sideCollapsible:before, #informationFooter ul li a:hover { color: '.$color.'; }';
    $style .= '.dropdown-menu li > a:hover, .dropdown-submenu:hover>a { color: #ffffff; }';
	$style .= '#siteinfoLegal a { color: '.$color.' !important; }';
    $style .= '.big-direction-nav a:hover, .big-control-paging li a:hover, .big-control-paging li a.big-active, .button:hover, #navMain ul li a:hover, .contactDetails:hover, .dropdown-menu li > a:hover, .dropdown-submenu:hover>a { background: '.$color.'; }';  
    $style .= '.carousel-nav ul li a.grey-next:hover, .carousel-nav ul li a.grey-prev:hover { background: '.$color.'; color: #ffffff }';
    $style .= '.collapseFooter, .collapseFooter:hover, .collapseFooter.collapsed, .collapseFooter.collapsed:hover { background-color: '.$color.';}';
    $style .= '.search-top-header input[type="text"].m-wrap:focus { border: 1px solid '.$color.' !important; }'; 
    $style .= '.navbar .nav > li > a:focus, .navbar .nav > li > a:hover, .navbar .nav li.dropdown.open > .dropdown-toggle, .navbar .nav li.dropdown.active > .dropdown-toggle, .navbar .nav li.dropdown.open.active > .dropdown-toggle, a.dd-active, .indexProducts:hover .indexProductsInner, .gridItem:hover .gridItemInner { border-bottom: 2px solid '.$color.'; }';  
    $style .= '.nav-tabs > li > a:hover, .nav-tabs > .active > a, .nav-tabs > .active > a:hover { border-bottom: 1px solid '.$color.'; }'; 
    $style .= '#mainWrapper { border-top: 3px solid '.$color.'; }';
    $style .= '#footerWidgetWrapper { border-top: 2px solid '.$color.'; }';   
    $style .= '@media (max-width: 979px) { .dropdown-menu li > a:hover { color: #ffffff !important; } .navbar .nav > li > a:focus, .navbar .nav > li > a:hover, .navbar .nav li.dropdown.open > .dropdown-toggle, .navbar .nav li.dropdown.active > .dropdown-toggle, .navbar .nav li.dropdown.open.active > .dropdown-toggle, a.dd-active { border: none !important; } #topMobileMenu.collapsed, #topMobileMenu, #topMobileMenu:hover { background: '.$color.'; } #topMobileMenu.collapsed:hover, .navbar .nav > li > a:focus, .navbar .nav > li > a:hover, li.level1 > a:hover, li.level2 a:hover, .headerCollapsible, #mobile-menu li a:hover, .headerCollapsible:hover { background: '.$color.'; color: #ffffff } .navbar .nav li.dropdown.open > .dropdown-toggle:hover, .navbar .nav li.dropdown.active > .dropdown-toggle:hover, .navbar .nav li.dropdown.open.active > .dropdown-toggle:hover { background: '.$color.' !important; } }';
    $style .= '@media (max-width: 480px) { .nav-tabs > li > a:hover, .nav-tabs > .active > a, .nav-tabs > .active > a:hover { border: none } .search-top-header input[type="text"].m-wrap:focus { border: 1px solid #409F89 !important; } }';  	
    $style .= '</style>' . "\n";
      
    return $style;
      
  }

  function rev_change_background($bg='noisy-grid'){
    if(defined('REVELATION_PATTERN') && REVELATION_PATTERN != ''){
        $bg = REVELATION_PATTERN;    
    }
    $style = '<style type="text/css">';
    if($bg=='none'){
        $style .= 'body { background: #ffffff; }'; 
    }else{
        $style .= 'body { background: #eeeeee url("' . DIR_WS_TEMPLATE_IMAGES . $bg .'.png"); }'; 
    } 
    $style .= '</style>' . "\n";  
    
    return $style;   
  }

  function rev_has_category_subcategories($category_id) {
    global $db;
    $child_category_query = "select count(*) as count
                             from " . TABLE_CATEGORIES . "
                             where categories_status = 1 and 
                             parent_id = '" . (int)$category_id . "'";

    $child_category = $db->Execute($child_category_query);

    if ($child_category->fields['count'] > 0) {
      return true;
    } else {
      return false;
    }
  }
  
  function rev_social_style(){
    $style = '<style type="text/css">';
    $style .= '.social.facebook:hover { background: #3B5998; color: #ffffff; }';
    $style .= '.social.twitter:hover { background: #00a0d1; color: #ffffff; }';
    $style .= '.social.gplus:hover { background: #db5a3c; color: #ffffff; }';
    $style .= '.social.pinterest:hover { background: #910101; color: #ffffff; }'; 
    $style .= '.social.youtube:hover { background: #b91f1f; color: #ffffff; }';
    $style .= '.social.skype:hover { background: #12a5f4; color: #ffffff; }'; 
    $style .= '</style>' . "\n";
  
    return $style;
  }

